home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / OpenStep / Old_Demos / GLaux / cone_ball.c next >
C/C++ Source or Header  |  1998-12-15  |  2KB  |  81 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "GL/osmesa.h"
  4.  
  5. int gl_width=480;
  6. int gl_height=480;
  7.  
  8. void init(void)
  9. {
  10.    GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
  11.    GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
  12.    GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  13.    GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
  14.  
  15.    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  16.    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  17.    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  18.    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  19.     
  20.    glEnable(GL_LIGHTING);
  21.    glEnable(GL_LIGHT0);
  22.    glEnable(GL_DEPTH_TEST);
  23. }
  24.  
  25. /*
  26.  * reshape simply creates an orthographic projection
  27.  * within the viewport.
  28.  */
  29. void reshape(int w, int h)
  30. {
  31.    glViewport(0,0,w,h);
  32.    glMatrixMode(GL_PROJECTION);
  33.    glLoadIdentity();
  34.    glOrtho(-2.5, 2.5, -2.5, 2.5, -5.0, 5.0);
  35.  
  36.    glMatrixMode(GL_MODELVIEW);
  37.    glLoadIdentity();
  38. }
  39.  
  40. void display(void)
  41. {
  42.    GLfloat red_mat[]   = { 1.0, 0.0, 0.0, 0.5 };
  43.    GLfloat green_mat[] = { 0.0, 1.0, 0.0, 0.5 };
  44.    GLfloat blue_mat[]  = { 0.0, 0.0, 1.0, 0.5};
  45.  
  46.    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  47.  
  48.    glPushMatrix();
  49.    glRotatef(20.0, 1.0, 0.0, 0.0);
  50.  
  51.    glPushMatrix();
  52.    glTranslatef(-0.75, 0.5, 0.0); 
  53.    glRotatef(90.0, 1.0, 0.0, 0.0);
  54.    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_mat );
  55.    auxSolidTorus(0.275, 0.85);
  56.    glPopMatrix();
  57.  
  58.    glPushMatrix();
  59.    glTranslatef(-0.75, -0.5, 0.0); 
  60.    glRotatef(270.0, 1.0, 0.0, 0.0);
  61.    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green_mat );
  62.    auxSolidCone(1.0, 2.0);
  63.    glPopMatrix();
  64.  
  65.    glPushMatrix();
  66.    glTranslatef(0.75, 0.0, -1.0);
  67.    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
  68.    auxSolidSphere(1.0);
  69.    glPopMatrix();
  70.  
  71.    glPopMatrix();
  72. }
  73.  
  74. void render_image(void)
  75. {
  76.     init();
  77.     reshape(gl_width,gl_height);
  78.     display();
  79. }
  80.  
  81.